package com.sinosoft.perfect.system._display.service;

import java.sql.SQLException;
import java.util.List;

import com.sinosoft.perfect.system._.po.TDisplay;
import com.sinosoft.perfect.system._.util.Producer;
import com.sinosoft.perfect.system._display.dao.IDisplayDAO;

public class DisplayServiceImpl implements IDisplayService {

	private IDisplayDAO displayDAO;

	public void setDisplayDAO(IDisplayDAO displayDAO) {
		this.displayDAO = displayDAO;
	}

	@Override
	public void deleteTDisplayByPK(TDisplay tdisplay) throws SQLException {
		displayDAO.deleteTDisplayByPK(tdisplay);
	}

	@Override
	public String insertByTDisplay(TDisplay tdisplay) throws SQLException {
		String id = Producer.generateIdOfTen();
		tdisplay.setFrameModelId(id);
		tdisplay.setFrameDefault("0");
		tdisplay.setStatus("1");
		displayDAO.insertByTDisplay(tdisplay);
		return id;
	}

	@Override
	public List<TDisplay> selectByTDisplay(TDisplay tdisplay) throws SQLException {
		return displayDAO.selectByTDisplay(tdisplay);
	}

	@Override
	public void updateTDisplayByPK(TDisplay tdisplay) throws SQLException {
		displayDAO.updateTDisplayByPK(tdisplay);
	}

	@Override
	public void updateTDisplayDefaultModelAndAnotherNormal(TDisplay tdisplay) throws SQLException {
		TDisplay t = new TDisplay();
		t.setFrameDefault("0");
		displayDAO.updateTDisplayByPK(t);
		displayDAO.updateTDisplayByPK(tdisplay);
	}

	@Override
	public TDisplay selectTDisplayDefault() throws SQLException {
		TDisplay td = new TDisplay();
		td.setFrameDefault("1");
		td.setStatus("1");
		List<TDisplay> l = this.selectByTDisplay(td);
		return (l != null ? l.get(0) : td);
	}

}
